home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 2.4 KB | 101 lines |
- package client;
-
- import java.awt.*;
- import java.util.Date;
- import java.util.StringTokenizer;
- import java.io.IOException;
-
- public class EdnaUI extends Panel implements CanUpdate {
- private static final int MAX_SEATS = 5;
-
- private List passengerList;
- private Button reserve;
-
- public EdnaUI() {
- setLayout(new BorderLayout());
-
- Panel p;
- p = new Panel();
-
- p.add(new Label("Date: 4/10/97"));
- p.add(new Label("Flight #: 100"));
-
- add("North", p);
-
- passengerList = new List(5, false);
- add("Center", passengerList);
-
- p = new Panel();
- reserve = new Button("new reservation");
- p.add(reserve);
-
- add("South", p);
-
- }
-
- /**
- * Show frame to make a new reservation when the user clicks
- * the "new reservation" button.
- * Show frame to delete a reservation when the user double-clicks
- * the list.
- */
- public boolean action(Event e, Object what) {
- try {
- if (e.target == reserve)
- showNewWindow();
- else if (e.target == passengerList)
- showDeleteWindow();
- } catch (IOException x) {
- System.out.println("could not edit passenger list");
- }
-
- return super.action(e, what);
- }
-
- private void showDeleteWindow() throws IOException {
- Frame pass;
-
- // Get the selected entry in the list, if there is one.
- String name = passengerList.getSelectedItem();
- if (name != null) {
- pass = new DeletePassenger(name, this);
- pass.pack();
- pass.show();
- }
- }
-
- private void showNewWindow() throws IOException {
- Frame pass;
-
- pass = new NewPassenger(this);
- pass.pack();
- pass.show();
- }
-
-
- public void updateUI() {
- String[] reservations;
- try {
- reservations = new Client().getPassengerList();
- } catch (IOException x) {
- System.out.println("Unable to show list");
- System.out.println(x.getMessage());
- return;
- }
- passengerList.clear();
-
- int total = reservations.length;
- for (int i = 0; i < total; i++)
- passengerList.addItem(reservations[i]);
-
- // Update the "make reservation" button as appropriate.
- if (reservations.length == MAX_SEATS)
- reserve.enable(false);
- else
- reserve.enable(true);
-
- validate();
- }
-
- }
-